import request from "@/utils/request";
import type { UserInfo } from "./type";


export const getUserInfo = () => {
    return request.get("/user/info");
}

export const getUserInfoById = (userId: string) => {
    return request.get("/user/info", {
        params: {
            'userId': userId
        }
    });
}

export const getUserList = () => {
    return request.get("/user/list");
}

export const getUserInfoList = async () => {
    const res = await request.get("/user/info/list");
    const userInfoList = res.data as UserInfo[];
    return userInfoList;
}

export const searchUserList = (keyword: string) => {
    return request.get("/user/list/search", {
        params: {
            'keyword': keyword
        }
    });
}

export const followUser = (followeeId: string) => {
    return request.post("/user/follow?followeeId=" + followeeId)
}

export const deleteUser = (userId: string) => {
    return request.delete("/user/delete", {
        params: {
            "userId": userId
        }
    })
}

export const editUserInfo = (userInfo: UserInfo) => {
    return request.put("/user/info/edit", userInfo)
}

export const editPassword = (userId: string, password: string) => {
    return request.put("/user/password/edit", {
        "id": userId,
        "password": password
    })
}

export const uploadAvatar = (avatar: File) => {
    return request.post("/user/avatar/upload", {
        "avatar": avatar
    }, {
        headers: {
            "Content-Type": "multipart/form-data"
        }
    });
}